<?php
$tb=array("drug","user","history","drug_history","hospital");
function C($a){
	include "db2.php";
	return $db[$a];
}
debugBreak();
$my_con=mysql_connect(C('DB_HOST').":".C('DB_PORT'),C('DB_USER'),C('DB_PWD'));
if(!$my_con){
		die('无法连接'.mysql_error());
	}
mysql_select_db(C('DB_NAME'),$my_con);

//取得表字段名
$query="SELECT * from ".C('DB_PREFIX').$tb[4];
mysql_query("SET NAMES 'UTF8'");
$result=mysql_query($query,$my_con);
$arr="";
for($i=1;$i<mysql_num_fields($result);$i++){
	$ziduan=mysql_field_name($result,$i);
	$arr[$i]=$ziduan;
}
//将取得的字段名数组以,拼接为字符串
$zichuan=implode(",",$arr);
echo $zichuan."<br/>";
//建立初始数据
$contactPhone=13800138000;
$num=0;
require "n.php";
foreach($name as $contact) {
	$b="";
	$rand=rand(2,4);
	for($n=1;$n<=$rand;$n++){
		$b=$b.getRandomName();
	}
	//拼接医院名称
	$hname="'中国".$b."人民医院'";

	$b="";
	$rand=rand(2,5);
	for($n=1;$n<=$rand;$n++){
		$b=$b.getRandomName();
	}
	//拼接地址
	$localarr=array('南城区','莞城区','东城区','大朗镇','黄江镇','横沥镇','长安镇','大岭山镇','松山湖镇','寮步镇','樟木头镇','桥头镇');
	$count=count($localarr);
	$rand=rand(0,$count-1);
	$rands=rand(1,2000);
	$localarrs=$localarr["$rand"];
	$localAddress="'广东省东莞市".$localarrs.$b."街".$rands."号'";
	
	//拼接医院联系电话
	//$callNo=strval(""0".rand(717,755)."-".rand(800820,880820)");

	$b="";
	$rand=rand(1,2);
	for($n=1;$n<=$rand;$n++){
	$b=$b.getRandomName();
	}
	//拼接contact字段联系人
	$contact="'".$contact.$b."'";
	//产生联系电话
	//$contactPhone=$contactPhone+1;
	$contactPhone=rand(130,139).rand(5100,5800).rand(1818,8181);
	$contactPhone="'".$contactPhone."'";
	//echo $hname."  ".$local."  ".$call."  ".$contact."  ".$contactPhone."<br/>";

	$exec="insert into ".C("DB_PREFIX").$tb[4]." (".$zichuan.") values (".$hname.",".$localAddress.",".$callNo.",".$contact.",".$contactPhone.");";
	echo $exec."<br/>";
	mysql_query($exec,$my_con);
	if($erro=mysql_error()) echo $num." 次错误！！".$erro."<br/>";
	else echo $num . '次成功<br/>';
	
	$num=$num+1;
	
}
mysql_close($my_con);

?>